package com.gitee.mrj.aiboot.core.sf.generators.ui.widget;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.gitee.mrj.aiboot.annotation.config.sf.ui.widget.SFRadioWidget;
import com.gitee.mrj.aiboot.core.sf.generators.FormDefinitionGenerator;
import com.gitee.mrj.aiboot.core.sf.generators.UIForm;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

@Component
public class SFRadioWidgetGenerator implements FormDefinitionGenerator {
    @Override
    public void generate(UIForm root, Field field, UIForm node) {
        SFRadioWidget widget = AnnotatedElementUtils.findMergedAnnotation(field, SFRadioWidget.class);
        generate(node, widget);
    }

    private void generate(UIForm node, SFRadioWidget widget) {
        ObjectNode ui = node.getUi();
        ui.put("widget", "radio");
        ui.put("styleType", widget.styleType().value());
        ui.put("buttonStyle", widget.buttonStyle().value());
    }


    @Override
    public Class[] supports() {
        return new Class[]{SFRadioWidget.class};
    }
}
